#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "debug.h"
#include "LinkedList.h"

bool once = FALSE;

/* returns a random integer in given range */
int get_rand() {
	if(!once) {
		srand((unsigned)time(NULL));
		once = TRUE;
	}
	return 1+rand() % 60;
}

int main (int argc, const char * argv[]) {

	/* create list */
	List* liste = List_create();

	/* fill the list with random items */
	for(int i = 0; i < 3; i++) {
		List_addItem(liste, get_rand());
		List_addAfter(liste, get_rand(), get_rand());
	}

	/* sort the list */
	List_sortById(liste);
	printf("items in list: %d\n", List_countItems(liste));

	/* get the list as array */
	int* ListAsArray = List_getAsArray(liste);
	for(int i=0;i < List_countItems(liste);i++) {
		printf("ListAsArray[%d]: %d\n", i, ListAsArray[i]);
	}

	/* cleanup list array */
	free(ListAsArray);

	/* remove list */
	List_remove(liste);

	return 0;
}
